
*********Create clusters at the bank level for exposure to different NAICS 3-digit industries**************


******************************************************************************
use "$LocalData\BankLevelAnalysis.dta", clear

qui tab year, gen(year_)

*Deposits by Deciles
noi display "Deposit by Deciles regressions."

gen temp = 1 if small==1 & year==2002
bysort cert: egen small2002 = max(temp)
drop temp

sort cert year
merge m:1 cert using "$LocalData\BankCluster3_2013.dta"
keep if _merge==3
* Restrict to banks with deposit growth positive or negative 500% or less

*local Filters year>2002 & abs(bank_busdep)<=5 



sort cert year
local filterbus abs(bank_busdep)<1  & abs(bank_hhdep)<1   & year>2013 &  asset<10000000 & bank_busdep!=0 & L.busdep!=.
local filterHH  abs(bank_hhdep)<1   & abs(bank_busdep)<1  & year>2013 &  asset<10000000 & bank_busdep!=0 & L.busdep!=.


eststo: reg bank_lndep bank_gSmallFirm1  year_* if `filterbus', vce(cluster cluster3)  
outreg2 using "$LocalData\Tables\BankLevelBusDeposits", tex replace ///
	ctitle("$\Delta$ln(HH+BusDep)") keep(bank_gSmallFirm1) ///
	addtext(REG, OLS, YEAR FE, YES, Bank FE, NO, YRS, 2014-2016)

eststo: reg bank_hhbus bank_gSmallFirm1  year_* if `filterbus', vce(cluster cluster3)  
outreg2 using "$LocalData\Tables\BankLevelBusDeposits", tex append ///
	ctitle("$\Delta$ln(HH+BusDep)") keep(bank_gSmallFirm1) ///
	addtext(REG, OLS, YEAR FE, YES, Bank FE, NO, YRS, 2014-2016)

eststo: reg bank_busdep bank_gSmallFirm1  year_* if `filterbus', vce(cluster cluster3)  
outreg2 using "$LocalData\Tables\BankLevelBusDeposits", tex append ///
	ctitle("$\Delta$ln(BusDep)") keep(bank_gSmallFirm1) ///
	addtext(REG, OLS, YEAR FE, YES, Bank FE, NO, YRS, 2014-2016)

eststo: reg bank_hhdep bank_gSmallFirm1  year_* if `filterHH', vce(cluster cluster3)  
outreg2 using "$LocalData\Tables\BankLevelBusDeposits", tex append ///
	ctitle("$\Delta$ln(HHDep)") keep(bank_gSmallFirm1 `controls') ///
	addtext(REG, OLS, YEAR FE, YES, Bank FE, NO, YRS, 2014-2016)

eststo: reg bank_gSmallFirm1 bank_bartikGS1  year_* if `filterbus', cluster(cluster3)
outreg2 using "$LocalData\Tables\BankLevelBusDeposits", tex append ///
	ctitle("$\Delta$ln(SmEmp)") keep(bank_gSmallFirm1 bank_bartikGS1 `controls') ///
	addtext(REG, OLS, YEAR FE, YES, Bank FE, NO, YRS, 2014-2016)

	
	
eststo: ivreg2 bank_lndep (bank_gSmallFirm1 = bank_bartikGS1 )  year_* if `filterbus', cluster(cluster3)
	local widstat = round(`e(widstat)',0.1)	
outreg2 using "$LocalData\Tables\BankLevelBusDeposits", tex append ///
	ctitle("$\Delta$ln(HH+BusDep)") keep(bank_gSmallFirm1 bank_bartikGS1 `controls') ///
	addtext(REG, 2SLS, YEAR FE, YES, Bank FE, NO, YRS, 2014-2016, F-Stat, `widstat')

	
	
eststo: ivreg2 bank_hhbus (bank_gSmallFirm1 = bank_bartikGS1 )  year_* if `filterbus', cluster(cluster3)
	local widstat = round(`e(widstat)',0.1)	
outreg2 using "$LocalData\Tables\BankLevelBusDeposits", tex append ///
	ctitle("$\Delta$ln(HH+BusDep)") keep(bank_gSmallFirm1 bank_bartikGS1 `controls') ///
	addtext(REG, 2SLS, YEAR FE, YES, Bank FE, NO, YRS, 2014-2016, F-Stat, `widstat')
	
eststo: ivreg2 bank_busdep (bank_gSmallFirm1 = bank_bartikGS1 )  year_* if `filterbus', cluster(cluster3)
	local widstat = round(`e(widstat)',0.1)	
outreg2 using "$LocalData\Tables\BankLevelBusDeposits", tex append ///
	ctitle("$\Delta$ln(BusDep)") keep(bank_gSmallFirm1 bank_bartikGS1 `controls') ///
	addtext(REG, 2SLS, YEAR FE, YES, Bank FE, NO, YRS, 2014-2016, F-Stat, `widstat')

eststo: ivreg2 bank_hhdep (bank_gSmallFirm1 = bank_bartikGS1 )  year_* if `filterHH', cluster(cluster3)
	local widstat = round(`e(widstat)',0.1)	
outreg2 using "$LocalData\Tables\BankLevelBusDeposits", tex append ///
	ctitle("$\Delta$ln(HHDep)") keep(bank_gSmallFirm1 bank_bartikGS1 `controls') ///
	addtext(REG, 2SLS, YEAR FE, YES, Bank FE, NO, YRS, 2014-2016, F-Stat, `widstat')


